package com.meilai.project.mapper.business.building;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.meilai.project.entity.business.building.BuildingAreaPoint;
import com.meilai.project.vo.business.building.BuildingAreaDetailPointVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface BuildingAreaPointMapper extends BaseMapper<BuildingAreaPoint> {
    @Select("SELECT " +
            "bap.media_type_id AS id " +
            ",bap.num AS num " +
            ",mt.`name` AS `name` " +
            "FROM building_area_point bap " +
            "LEFT JOIN media_type mt ON bap.media_type_id=mt.id " +
            "WHERE bap.building_area_id=#{building_area_id}")
    List<BuildingAreaDetailPointVO> getDetailPoints(@Param("building_area_id") Long building_area_id);

    @Select("<script> " +
            "SELECT  " +
            "mp.building_area_id,mp.media_type_id,count(1) AS num " +
            "FROM media_point mp  " +
            "WHERE mp.deleted_at IS NULL AND mp.`status`=1 " +
            "<if test=\"building_area_id != null \"> " +
            "  AND mp.building_area_id = #{building_area_id} " +
            "</if>" +
            "GROUP BY mp.building_area_id,mp.media_type_id" +
            "</script>")
    List<BuildingAreaPoint> getBuildingPoints(@Param("building_area_id") Long building_area_id);
}
